package com.qsw.refreshrecyclerview.test;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qsw.refreshrecyclerview.R;
import com.qsw.refreshrecyclerview.RefreshRecyclerView.adapter.RefreshRecyclerViewAdapter;

import java.util.List;

/**
 * 书籍列表表格布局适配器
 */
public class RRVTestRecyclerViewGridAdapter extends RefreshRecyclerViewAdapter<String, RRVTestRecyclerViewGridAdapter.TestRcvViewHolder> {

    private int mNumColumns;

    public RRVTestRecyclerViewGridAdapter(List<String> data, int numColumns) {
        super(data);
        this.mNumColumns = numColumns;
    }

    @NonNull
    @Override
    public TestRcvViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TestRcvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.rrv_test_grid_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull TestRcvViewHolder holder, int position) {
        String str = getItemBean(position);
        holder.tvTest.setText(str);
        if (position % 2 == 0) {
            holder.tvTest.setBackgroundColor(Color.parseColor("#00CC00"));
        } else {
            holder.tvTest.setBackgroundColor(Color.parseColor("#0000CC"));
        }
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    class TestRcvViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTest;

        public TestRcvViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }

        private void initView(View view) {
            tvTest = view.findViewById(R.id.rrv_tv_test_grid_item);
        }
    }

}
